#ifndef _VMSA_H
#define _VMSA_H

#include <stdint.h>

typedef struct __attribute__ ((__packed__)) vmcb_seg_t {
    uint16_t selector;
    uint16_t attrib;
    uint32_t limit;
    uint64_t base;
} vmcb_seg;


/* Save area definition for CSV guests */
typedef struct __attribute__((packed)) csv_save_area_t {
    vmcb_seg es;
    vmcb_seg cs;
    vmcb_seg ss;
    vmcb_seg ds;
    vmcb_seg fs;
    vmcb_seg gs;
    vmcb_seg gdtr;
    vmcb_seg ldtr;
    vmcb_seg idtr;
    vmcb_seg tr;
    uint64_t vmpl0_ssp;
    uint64_t vmpl1_ssp;
    uint64_t vmpl2_ssp;
    uint64_t vmpl3_ssp;
    uint64_t u_cet;
    uint8_t reserved_0xc8[2];
    uint8_t vmpl;
    uint8_t cpl;
    uint8_t reserved_0xcc[4];
    uint64_t efer;
    uint8_t reserved_0xd8[104];
    uint64_t xss;
    uint64_t cr4;
    uint64_t cr3;
    uint64_t cr0;
    uint64_t dr7;
    uint64_t dr6;
    uint64_t rflags;
    uint64_t rip;
    uint64_t dr0;
    uint64_t dr1;
    uint64_t dr2;
    uint64_t dr3;
    uint64_t dr0_addr_mask;
    uint64_t dr1_addr_mask;
    uint64_t dr2_addr_mask;
    uint64_t dr3_addr_mask;
    uint8_t reserved_0x1c0[24];
    uint64_t rsp;
    uint64_t s_cet;
    uint64_t ssp;
    uint64_t isst_addr;
    uint64_t rax;
    uint64_t star;
    uint64_t lstar;
    uint64_t cstar;
    uint64_t sfmask;
    uint64_t kernel_gs_base;
    uint64_t sysenter_cs;
    uint64_t sysenter_esp;
    uint64_t sysenter_eip;
    uint64_t cr2;
    uint8_t reserved_0x248[32];
    uint64_t g_pat;
    uint64_t dbgctl;
    uint64_t br_from;
    uint64_t br_to;
    uint64_t last_excp_from;
    uint64_t last_excp_to;
    uint8_t reserved_0x298[80];
    uint32_t pkru;
    uint32_t tsc_aux;
    uint8_t reserved_0x2f0[24];
    uint64_t rcx;
    uint64_t rdx;
    uint64_t rbx;
    uint64_t reserved_0x320;	/* rsp already available at 0x01d8 */
    uint64_t rbp;
    uint64_t rsi;
    uint64_t rdi;
    uint64_t r8;
    uint64_t r9;
    uint64_t r10;
    uint64_t r11;
    uint64_t r12;
    uint64_t r13;
    uint64_t r14;
    uint64_t r15;
    uint8_t reserved_0x380[16];
    uint64_t guest_exit_info_1;
    uint64_t guest_exit_info_2;
    uint64_t guest_exit_int_info;
    uint64_t guest_nrip;
    uint8_t  reserved_0x3b0[8];
    uint64_t vintr_ctrl;
    uint64_t guest_exit_code;
    uint64_t virtual_tom;
    uint64_t tlb_id;
    uint64_t pcpu_id;
    uint64_t event_inj;
    uint64_t xcr0;
    uint8_t reserved_0x3f0[16];

    /* Floating point area */
    uint64_t x87_dp;
    uint32_t mxcsr;
    uint16_t x87_ftw;
    uint16_t x87_fsw;
    uint16_t x87_fcw;
    uint16_t x87_fop;
    uint16_t x87_ds;
    uint16_t x87_cs;
    uint64_t x87_rip;
    uint8_t fpreg_x87[80];
    uint8_t fpreg_xmm[256];
    uint8_t fpreg_ymm[256];
} csv_save_area;

#define  VMSA_SIZE  4096

#endif
